import os


def load_last_processed_seq(output_path):
    seq_file = os.path.join(output_path, 'seq.txt')
    try:
        with open(seq_file, 'r') as f:
            last_processed_seq = int(f.read().strip())
    except (FileNotFoundError, ValueError):
        # 如果文件不存在或内容不是整数，则从头开始
        last_processed_seq = 0
    return last_processed_seq


def save_processed_seq(output_path, last_processed_seq):
    seq_file = os.path.join(output_path, 'seq.txt')
    with open(seq_file, 'w') as f:
        f.write(str(last_processed_seq))


def save_total_number(output_path, total_number):
    total_number_file_path = os.path.join(output_path, 'total_number.txt')
    with open(total_number_file_path, 'w') as f:
        f.write(str(total_number))


def load_total_number(output_path):
    total_number_file_path = os.path.join(output_path, 'total_number.txt')
    try:
        with open(total_number_file_path, 'r') as f:
            total_number = int(f.read().strip())
    except (FileNotFoundError, ValueError):
        # 如果文件不存在或内容不是整数，则从头开始
        total_number = 0
    return total_number
